<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="昵称" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list">
      <el-table-column label="昵称" align="center" prop="nickName" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="头像" align="center" prop="avatar" >
        <template slot-scope="{row}">
          <el-image v-if="row.avatar"
            style="width: 100px; height: 100px"
            :src="row.avatar" 
            :preview-src-list="[row.avatar]">
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="注册时间" align="center" prop="registerTime"/>
      <el-table-column label="注册社交类型" align="center" prop="registerSocialType" >
        <template slot-scope="{row}">
          <dict-tag :options="dict.type.user_register_type" :value="row.registerSocialType"/>
        </template>
      </el-table-column>
      <el-table-column label="最后登录IP" align="center" prop="loginIp"/>
      <el-table-column label="最后登录时间" align="center" prop="loginTime"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <el-button type="text" @click="handleUser(row,1)"
            v-hasPermi="['member:socialUser:list']">第三方用户
          </el-button>
          <el-button type="text" @click="handleUser(row,2)"
            v-hasPermi="['pilot:pilotSocialUser:list']">飞手第三方用户
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body>
      <el-form :model="popQueryParams" ref="popQueryForm" size="small" :inline="true" v-show="popShowSearch" label-width="108px">
        <el-form-item label="手机号" prop="phone">
          <el-input
            v-model="popQueryParams.phone"
            placeholder="请输入手机号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="社交平台类型" prop="type">
          <el-select v-model="popQueryParams.type" clearable filterable placeholder="请选择社交平台类型">
            <el-option
              v-for="item in dict.type.user_register_type"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="popHandleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="popResetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <right-toolbar :showSearch.sync="popShowSearch" @queryTable="getPopList"></right-toolbar>
      </el-row>

      <el-table v-loading="popLoading" :data="popList">
        <el-table-column label="用户openid" align="center" prop="openid" />
        <el-table-column label="微信unionid" align="center" prop="unionid" />
        <el-table-column label="手机号" align="center" prop="phone"/>
        <el-table-column label="社交平台类型" align="center" prop="type" >
          <template slot-scope="{row}">
            <dict-tag :options="dict.type.user_register_type" :value="row.type"/>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="popTotal>0"
        :total="popTotal"
        :page.sync="popQueryParams.pageNum"
        :limit.sync="popQueryParams.pageSize"
        @pagination="getPopList"
      />
      <div slot="footer" class="dialog-footer">
        <el-button @click="open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMemberUser,listSocialUser,listPilotSocialUser, } from "@/api/user/userList";
export default { 
  name: "UserList",
  dicts: ['user_register_type',],
  components: { },
  data() {
    return {
      // 遮罩层
      loading: true,
      popLoading: true,
      // 显示搜索条件
      showSearch: true,
      popShowSearch: true,
      // 总条数
      total: 0,
      popTotal: 0,
      // 表格数据
      list: [],
      popList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        phone: undefined,nickName: undefined,
      },
      // 查询参数
      popQueryParams: {
        pageNum: 1,
        pageSize: 10,
        type: undefined,phone: undefined,
      },
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      popType:1,//弹窗显示类型
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleUser(e,type){//查询用户
      this.popType = type
      this.popQueryParams.userId = e.id
      this.open = true
      this.title = type == 2 ? '飞手第三方用户' : '第三方用户'
      this.popResetQuery()
    },
    /** 查列表 */
    getList() {
      this.loading = true;
      listMemberUser(this.queryParams).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    popHandleQuery() {
      this.popQueryParams.pageNum = 1;
      this.getPopList();
    },
    /** 重置按钮操作 */
    popResetQuery() {
      this.resetForm("popQueryForm");
      this.popHandleQuery();
    },
    async getPopList(){//获取弹窗列表数据
      this.popLoading = true
      let popQueryParams = {...this.popQueryParams}
      let api = this.popType == 2 ? listPilotSocialUser : listSocialUser
      let res = await api(popQueryParams)
      let rows = res.rows || []
      this.popList = rows
      this.popTotal = res.total || 0
      this.popLoading = false
    },
  }
};
</script>